package com.devunion.bogdan.util;

import java.util.Arrays;
import java.util.Vector;

/**
 * User: Leska
 * Date: 23.10.2004
 * Time: 20:58:45
 */

public class PathHelper {
    private static String sep;
    private static Vector pathVariables;

    static {
        sep = System.getProperty("file.separator");
        pathVariables = new Vector(Arrays.asList(new String[]{"$input$", "$output$", "$conf$", "$root$", "$projects$"}));
    }

    public static String getInputPath() {
        return System.getProperty("user.dir") + sep + "pyeditor" + sep + "input" + sep;
    }

    public static String getOutputPath() {
        return System.getProperty("user.dir") + sep + "pyeditor" + sep + "output" + sep;
    }

    public static String getConfigPath() {
        return System.getProperty("user.dir") + sep + "pyeditor" + sep + "conf" + sep;
    }

    public static String getRootPath() {
        return System.getProperty("user.dir") + sep + "pyeditor" + sep;
    }

    public static String getProjectsPath() {
        return System.getProperty("user.dir") + sep + "pyeditor" + sep + "projects" + sep;
    }

    /**
     * Checks if system path variable with <i>var</i> name exists.
     *
     * @param var - variable name
     * @return
     */
    public static boolean isPathVar(String var) {
        return pathVariables.contains(var);
    }

    /**
     * Returns path according to given variable
     * @param var path variable name
     * @return according path
     * @throws IllegalArgumentException if the variable does not exists.
     */
    public static String getPathByVar(String var){
        if (var.equals("$input$")) {
            return getInputPath();
        }
        if (var.equals("$output$")) {
            return getOutputPath();
        }
        if (var.equals("$conf$")) {
            return getConfigPath();
        }
        if (var.equals("$root$")) {
            return getRootPath();
        }
        if (var.equals("$projects$")) {
            return getProjectsPath();
        }
        throw new IllegalArgumentException("Path variable " + var + " doesn't exists.");
    }
}
